package com.brossdong.socket.netty.test;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * Created by brossdong on 2018/2/11.
 */
public class Client {

    public static void main(String[] args) throws Exception {

        EventLoopGroup group = new NioEventLoopGroup();

        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(NioSocketChannel.class)
         .handler(new ChannelInitializer<SocketChannel>() {
             @Override
             protected void initChannel(SocketChannel sc) throws Exception {
                 sc.pipeline().addLast(new ClientHandler());
             }
         })
         .option(ChannelOption.SO_BACKLOG, 128)
         .option(ChannelOption.SO_KEEPALIVE, true);


        ChannelFuture f = b.connect("127.0.0.1",8765).sync();

        //buf
        f.channel().write(Unpooled.copiedBuffer("777".getBytes()));
        f.channel().flush();

        f.channel().closeFuture().sync();
        group.shutdownGracefully();


    }

}
